package structural_pattern.flyweight_pattern;

import java.util.Hashtable;

/**
 * 围棋棋子工厂类：享元工厂类，使用单例模式进行设计
 */
public class IgonChessFactory {
    private static IgonChessFactory instance = new IgonChessFactory();
    private static Hashtable hashtable;

    private IgonChessFactory(){
        hashtable = new Hashtable();
        IgoChessman black,white;
        black = new BlackIgoChessman();
        white = new WhiteIgoChessman();
        hashtable.put("b",black);
        hashtable.put("w",white);
    }

    public static IgonChessFactory getInstance(){

        return instance;
    }

    public  IgoChessman getIgoChessman(String color){
        return (IgoChessman) hashtable.get(color);
    }
}
